﻿using System;
using System.Windows.Forms;

namespace DevelopersTestPad.Worksheets
{
    /// <summary>
    /// This static factory class creates <see cref="WorksheetView"/> instances.
    /// </summary>
    internal static class WorksheetViewFactory
    {
        /// <summary>
        /// Creates a new <see cref="WorksheetView"/> for the specified <see cref="Worksheet"/>.
        /// </summary>
        /// <param name="worksheet">Worksheet</param>
        /// <returns>WorksheetView</returns>
        public static WorksheetView CreateWorksheetView(Worksheet worksheet)
        {
            WorksheetView view;

            switch (worksheet.Type)
            {
                case WorksheetType.CSharpScript:
                    view = new DotNet.DotNetWorksheetView();
                    break;
                case WorksheetType.VisualBasicScript:
                    view = new DotNet.DotNetWorksheetView();
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            view.Worksheet = worksheet;
            view.Dock = DockStyle.Fill;
            view.Visible = true;

            view.Initialize();

            return view;
        }
    }
}
